package com.czy.owner.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.FindActivityModel;
import com.czy.owner.entity.ShoppingModel;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

import java.io.Serializable;


/**
 * Created by wangyang on 2017/5/15 0015.
 */

public class ShoppingStrategyAdapter extends RecyclerArrayAdapter<ShoppingModel.StrategyListBean>{
    private Context context;

    public ShoppingStrategyAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new ShoppingStrategyViewHolder(parent, context);
    }

    class ShoppingStrategyViewHolder extends BaseViewHolder<ShoppingModel.StrategyListBean> {

        private ImageView imgShoppingStrategy;
        private TextView tvShoppingStrategyTitle;
        private TextView tvShoppingStrategyTime;
        private TextView tvShoppingStrategyReadCount;

        public ShoppingStrategyViewHolder(ViewGroup parent, Context ctx) {
            super(parent, R.layout.item_shopping_strategy);
            imgShoppingStrategy = $(R.id.img_shopping_strategy);
            tvShoppingStrategyTitle = $(R.id.tv_shopping_strategy_title);
            tvShoppingStrategyTime = $(R.id.tv_shopping_strategy_time);
            tvShoppingStrategyReadCount = $(R.id.tv_shopping_strategy_read_count);
        }

        @Override
        public void setData(ShoppingModel.StrategyListBean data) {
            super.setData(data);
            tvShoppingStrategyTitle.setText(data.getTitle());
            tvShoppingStrategyReadCount.setText(data.getViewCount()+ "阅读");
            tvShoppingStrategyTime.setText(TimeUtils.getTimeRange(TimeUtils.formatTimeDifference(data.getCreateTime())));
            GlideUtils.loadImage(context, data.getCoverUrl(), imgShoppingStrategy, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);
        }
    }
}
